Technical Q&A JAVA28
Creating JNI Libraries with Project Builder


Q: How to I create a Mac OS X JNI (Java Native Interface) library with Project Builder?

A: Project builder does not have a template project, or a template target for JNI libraries. The following steps will create a Project Builder target for building a JNI library for Mac OS X.

  1. Under the Project Menu, add a new target.
  2. Select the target template called Library.
  3. Set the target name to be lib{libname}.jnilib as in "libhello.jnilib".
  4. Select the new target, and then a tab called Build Settings should appear in the pane next to the target's pane. Select the Build Settings target.
  5. Scroll down to the Search paths panel.
  6. Add the following path to the list of Headers (which is in the Search paths panel):
/System/Library/Frameworks/JavaVM.framework/Headers
  1. Scroll down to the Expert Build Settings panel.
  2. In the Expert Build Settings, delete the DYLIB_COMPATIBILITY_VERSION and the DYLIB_CURRENT_VERSION options. (The Delete key will delete them.)
  3. In the Expert Build Settings, change the LIBRARY_STYLE option to BUNDLE. (Double click in the value column of a build setting to change it.)
  4. Select the Files tab on the vertical pane to the left of the window.
  5. Add the Java-generated header files and the native implementations to the target.

Note:
JNI libraries must be in the path defined by the Java property "java.library.path" to be loaded with the System.loadLibrary("libname") method. To extend the java.library.path, define the environment variable DYLD_LIBRARY_PATH with the additional directories.



The default value of java.library.path in Mac OS X is:

.:/usr/lib:/usr/lib/java:/lib:/System/Library/
                   Framworks/JavaVM.framework/Versions/1.3/Libraries

Java applications built with Project Builder and MRJAppBuilder also search for libraries in the Contents/Resources/Java/ folder of the applications bundle.

[Jun 19 2001]


Developer Documentation | Technical Notes | Development Kits | Sample Code